package com.qfedu.controller;

import com.qfedu.entity.Askforleave;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.User;
import com.qfedu.service.AskforleaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/***
 *
 *   █████▒█    ██  ▄████▄   ██ ▄█▀       ██████╗ ██╗   ██╗ ██████╗
 * ▓██   ▒ ██  ▓██▒▒██▀ ▀█   ██▄█▒        ██╔══██╗██║   ██║██╔════╝
 * ▒████ ░▓██  ▒██░▒▓█    ▄ ▓███▄░        ██████╔╝██║   ██║██║  ███╗
 * ░▓█▒  ░▓▓█  ░██░▒▓▓▄ ▄██▒▓██ █▄        ██╔══██╗██║   ██║██║   ██║
 * ░▒█░   ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄       ██████╔╝╚██████╔╝╚██████╔╝
 *  ▒ ░   ░▒▓▒ ▒ ▒ ░ ░▒ ▒  ░▒ ▒▒ ▓▒       ╚═════╝  ╚═════╝  ╚═════╝
 *  ░     ░░▒░ ░ ░   ░  ▒   ░ ░▒ ▒░
 *  ░ ░    ░░░ ░ ░ ░        ░ ░░ ░
 *           ░     ░ ░      ░  
 */
@RestController
public class AskforleaveController {

    @Autowired
    private AskforleaveService askforleaveService;

    @RequestMapping("/AskForLeave/insertLeave.do")
    public ResponseData addAskForLeave(Askforleave askforleave , HttpServletRequest request){
        System.out.println("Askforleave:" + askforleave);
        User user = (User) request.getSession().getAttribute("user");
        int i = askforleaveService.addAskforleave(askforleave);
        askforleave.setUid(user.getId());
        ResponseData responseData = new ResponseData();
        if(i>0){
            responseData.setMsg("添加成功");
            responseData.setCode(0);
        }
        return responseData;
    }
    @RequestMapping("/AskForLeave/nodolist.do")
    public ResponseData<List<Askforleave>> findAskforleave(){
        ResponseData<List<Askforleave>> listResponseData = new ResponseData<>();

        List<Askforleave> askforleave = askforleaveService.findAskforleave();
        listResponseData.setCode(0);
        listResponseData.setData(askforleave);
        listResponseData.setMsg("成功");
        return listResponseData;
    }
}
